package com.bvgol.examples.nio;/**
 * @Classname TestFileChannelTransferFrom
 * @Description TODO
 * @Date 2021/6/18 9:15
 * @Created by GUOCHEN
 */

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.time.LocalDate;

/**
 * @program: my-spring-completely
 * @description: channel cp 文件
 * @author: GUOCHEN
 * @create: 2021/06/18 09:15
 */
public class TestFileChannelTransferFrom {
    public static void main(String[] args) throws Exception {
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;

        fileInputStream = new FileInputStream("D:\\idea_projects\\my-springboot-completely\\netty\\src\\main\\resources\\file01.txt");
        FileChannel inputStreamChannel = fileInputStream.getChannel();

        String filename = LocalDate.now().toString();

        System.out.println("filename = " + filename);
        fileOutputStream = new FileOutputStream("D:\\idea_projects\\my-springboot-completely\\netty\\src\\main\\resources\\"+filename+".txt");
        FileChannel outputStreamChannel = fileOutputStream.getChannel();
        outputStreamChannel.transferFrom(inputStreamChannel, 0, inputStreamChannel.size());
        fileInputStream.close();
        fileOutputStream.close();
        inputStreamChannel.close();
        outputStreamChannel.close();
    }
}
